package com.ibeeking.found.content.b.rest.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ibeeking.found.content.b.rest.service.IBroadcastGoodsService;
import com.ibeeking.found.content.service.common.param.BroadcastGoodsParam;
import com.ibeeking.found.content.service.common.query.BroadcastGoodsPageQuery;
import com.ibeeking.found.content.service.common.query.BroadcastGoodsQuery;
import com.ibeeking.found.content.service.common.vo.BroadcastGoodsVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName BroadcastController控制器
 * @Description
 * @Author ibeeking
 * @Date 2022-02-18 14:11
 **/
@RestController
@RequestMapping("/b/broadcast/v1/goods")
public class BroadcastGoodsController {

    @Resource
    private IBroadcastGoodsService broadcastGoodsServiceImpl;

    /**
     * --------货架商品
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "商品分页列表")
    @PostMapping(value = "/pageList")
    public Page<BroadcastGoodsVO> goodsPageList(@RequestBody BroadcastGoodsPageQuery pageQuery) {
        return broadcastGoodsServiceImpl.pageList(pageQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "商品列表")
    @PostMapping(value = "/list")
    public List<BroadcastGoodsVO> goodsList(@RequestBody BroadcastGoodsQuery broadcastGoodsQuery) {
        return broadcastGoodsServiceImpl.list(broadcastGoodsQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "商品添加")
    @PostMapping(value = "/add")
    public Boolean goodsAdd(@RequestBody @Validated BroadcastGoodsParam broadcastGoodsParam) {
        return broadcastGoodsServiceImpl.add(broadcastGoodsParam);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "批量商品添加")
    @PostMapping(value = "/batchAdd")
    public Boolean goodsBatchAdd(@RequestBody List<String> goodsIds) {
        return broadcastGoodsServiceImpl.batchAdd(goodsIds);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "商品修改")
    @PostMapping(value = "/modify")
    public Boolean goodsModify(@RequestBody @Validated BroadcastGoodsParam broadcastGoodsParam) {
        return broadcastGoodsServiceImpl.modify(broadcastGoodsParam);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "商品查看")
    @GetMapping(value = "/view/{id}")
    public BroadcastGoodsVO goodsView(@PathVariable("id") Long id) {
        return broadcastGoodsServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "商品删除")
    @PostMapping(value = "/del/{id}")
    public Boolean goodsDel(@PathVariable("id") Long id) {
        return broadcastGoodsServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "商品状态修改")
    @PostMapping(value = "/changeStatus/{id}/{status}")
    public Boolean goodsChangePublishStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return broadcastGoodsServiceImpl.changePublishStatus(id, status);
    }
}
